import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '@/views/Home.vue' //后续添加的Home组件
import Login from '../views/Login.vue'
import Category from '@/views/Category.vue'
import Cart from '@/views/Cart.vue'
import User from '@/views/User.vue'
import GoodDetail from '@/views/GoodDetail.vue'
import Setting from '../views/Setting.vue'
import ProductList from '../views/ProductList.vue'
import ProductDetail from '../views/ProductDetail.vue'
import AddressEdit from '../components/AddressEdit.vue'
import Address from '../views/Address.vue'
import CreateOrder from '../views/CreateOrder.vue'
import Order from '../views/Order.vue'
import OrderDetail from '../views/OrderDetail.vue'

//使用createRouter创建路由实例
const router = createRouter({
  history:createWebHashHistory(),//Hash模式：createWebHashHistory History模式：createWebHistory
  routes: [
    {
      path:'/',
      redirect: '/home' //重定向到/home路径下
    },
    {
      path:'/login',
      name: 'login', //登录和注册
      component: Login
    },
    {
      path: '/home',
      name: 'home',
      component: Home //首页
    },
    {
      path: '/category',
      name: 'category',
      component: Category //分类
    },
    {
      path: '/cart',
      name: 'cart',
      component: Cart //购物车
    },
    {
      path: '/user',
      name: 'user',
      component: User //我的
    },
    {
      path: '/good-detail',
      name: 'GoodDetail',
      component: GoodDetail //商品详情
    },
    {
      path: '/setting',
      name: 'Setting',
      component: Setting
    },
    {
      path: '/product-list',
      name: 'ProductList',
      component: ProductList
    },
    {
      path: '/product-detail/:id',
      name: 'ProductDetail',
      component: ProductDetail
    },
    {
      path: '/address-edit',
      name: 'address-edit',
      component: AddressEdit
    },
    {
      path: '/address',
      name: 'address',
      component: Address
    },
    {
      path: '/create-order',
      name: 'CreateOrder',
      component: CreateOrder
    },
    {
      path: '/order',
      name: 'order',
      component: Order
    },
    {
      path: '/order-detail',
      name: 'order-detail',
      component: OrderDetail
    }
  ]
})

//抛出路由实例，在main.js中引用
export default router